
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>
<div id="page-wrapper">


    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Các Kết Quả Đánh Giá Thái Độ</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Danh sách
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="col-lg-12">
                        <div class="form-group">
                                <label>Đợt đánh giá</label>
                                <input type="text" name="name" class="form-control" style="width: 50%;" readonly="readonly" value="<?php echo $evaluationInfo['name']; ?>" />
                            </div>
                        Area 
                        <select class="form-control display-inline" name="filter-region" style="width: 150px;">
                            <option value="all">Tất cả</option>
                            <?php foreach ($regions as $eachRegion) { ?>
                                <option value="<?php echo $eachRegion['rsm_code']; ?>" <?php echo ($filterRegion == $eachRegion['rsm_code']) ? 'selected="selected"' : ''; ?>><?php echo $eachRegion['region_name']; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Nhóm
                        <select class="form-control display-inline" name="filter-title" style="width: 100px;">
                            <option value="all">Tất cả</option>
                            <?php
                            foreach ($titles as $key => $value) {
                                ?>
                                <option value="<?php echo $value; ?>" <?php echo ($filterTitle == $value) ? 'selected="selected"' : ''; ?>><?php echo $key; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Supervisor 
                        <select class="form-control display-inline" name="filter-ss" style="width: 270px;">
                            <option value="all">Tất cả</option>
                            <?php foreach ($ssList as $eachSS) { ?>
                                <option value="<?php echo $eachSS['code']; ?>" <?php echo ($filterSS == $eachSS['code']) ? 'selected="selected"' : ''; ?>><?php echo $eachSS['name']; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Thái độ
                        <select class="form-control display-inline" name="filter-att" style="width: 170px;">
                            <option value="all" <?php echo ($filterAtt == 'all') ? 'selected="selected"' : ''; ?>>Tất cả</option>
                            <option value="done" <?php echo ($filterAtt == 'done') ? 'selected="selected"' : ''; ?>>Đã đánh giá</option>
                            <option value="not" <?php echo ($filterAtt == 'not') ? 'selected="selected"' : ''; ?>>Chưa đánh giá</option>
                            <?php
                            foreach ($attRatings as $key => $value) {
                                ?>
                                <option value="<?php echo $value['id']; ?>" <?php echo ($filterAtt == $value['id']) ? 'selected="selected"' : ''; ?>><?php echo $value['name']; ?></option>
                            <?php } ?>
                        </select>
                        <br><br>
                    </div>

                    <!--Thống kê-->
                    <div class="col-lg-4">
                        <table class="table table-bordered">
                            <tr><td>Số nhân viên</td><td><?php echo count($rows) ?></td></tr>
                            <?php if ($filterAtt == 'all') { ?>

                                <tr><td>Đã đánh giá</td><td><?php echo $numberDone ?></td></tr>
                                <tr><td>Chưa đánh giá</td><td><?php echo $numberNot ?></td></tr>
                            <?php } ?>
                            <?php if ($filterAtt == 'all' || $filterAtt == 'done') { ?>
                                <?php
                                foreach ($arNote as $key => $value) {
                                    ?>
                                    <tr><td><?php echo $arDic[$key] ?></td><td><?php echo $arNote[$key] ?></td></tr>
                                <?php } ?>

                            <?php } ?>
                        </table>
                    </div>

                    <div class="col-lg-12">
                        <?php
                        if ($rows == false) {
                            ?>
                            Hiện tại không có kết quả nào!
                            <br>
                        <?php } else { ?>

                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="att-detail-results">
                                    <thead>
                                        <tr>
                                            <th>TL code</th>
                                            <th>SS code</th>
                                            <th>RSM code</th>
                                            <!--<th width="40px">No</th>-->

                                            <th width="90px">Area</th>
                                            <th width="110px">Location</th>
                                            <th width="70px">Mã NV</th>
                                            <th width="50px">Title</th>
                                            <th>Họ và tên</th>

                                            <!--<th>Tên đợt</th>-->
                                            <th>Số điểm</th>
                                            <th>Xếp loại</th>
                                            <th>Xác nhận</th>
                                            <th>Supervisor</th>
                                            <th>Ngày đánh giá</th>
        <!--                                        <th>&nbsp;</th>-->
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $i = 1;
                                        foreach ($rows as $row) {
                                            ?>
                                            <tr>
                                                <td><?php echo $row['teamleader_code']; ?></td>
                                                <td><?php echo $row['supervisor_code']; ?></td>
                                                <td><?php echo $row['rsm_code']; ?></td>
                                                <!--<td><?php echo $i; ?></td>-->

                                                <td><?php echo $regionDic[$row['rsm_code']]; ?></td>
                                                <td><?php echo $row['location']; ?></td>
                                                <td><?php echo $row['code']; ?></td>
                                                <td><?php echo ($row['title']); ?></td>
                                                <td><?php echo $row['name']; ?></td>

                                                <!--<td style="vertical-align: middle;"><?php echo $evaluationInfo['name']; ?></td>-->
                                                <td style="vertical-align: middle;"><?php echo $row['attResult']['score']; ?></td>
                                                <td style="vertical-align: middle;"><?php echo color_attitude($row['attResult']['score'], $settings['att_high_score'], $settings['att_medium_score'], $row['attResult']['rating']); ?></td>
                                                <td><?php echo $row['attResult']['status']; ?></td>
                                                <td><?php echo $row['supervisor_name']; ?></td>
                                                <td style="vertical-align: middle;"><?php echo $row['attResult']['rated_day']; ?></td>

                                            </tr>

                                            <?php
                                            $i++;
                                        }
                                        ?>
                                    </tbody>
                                </table>

                            </div>
                        <?php } ?>
                    </div>
                    <br>
<!--                    <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/attitude_detail_results/add'); ?>"> <img src="<?php echo base_url(); ?>images/plus.png" title="Thêm bảng đánh giá mới"> Thêm bảng đánh giá mới</a>
                    <br>-->
                </div>
                <!-- /.panel-body -->
            </div>
        </div>
    </div>


</div>
<script>
    function search()
    {
        var region = "";
        var title = "";
        var att = "";
        var ss = "";

        $("select[name=filter-region] option:selected").each(function() {
            region = $(this).val();
        });
        $("select[name=filter-title] option:selected").each(function() {
            title = $(this).val();
        });
        $("select[name=filter-att] option:selected").each(function() {
            att = $(this).val();
        });
        $("select[name=filter-ss] option:selected").each(function() {
            ss = $(this).val();
        });
        window.location = '<?php echo site_url(get_folder($loggedUser['title']) . '/attitude_detail_results/index') ?>' + '/' + region + '/' + title + '/' + att+ '/' + ss;
    }

    $(document).ready(function() {
        var oTable = $('#att-detail-results').dataTable(
                {
                    "scrollX": true,
                    "sScrollX": "120%",
                    "columnDefs": [
                        {
                            "targets": [0],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        },
                        {
                            "targets": [1],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        },
                        {
                            "targets": [2],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        }
                    ]
                });

        $('select[name=filter-region]').change(function() {
            search();
        });

        $('select[name=filter-title]').change(function() {
            search();
        });
        $('select[name=filter-att]').change(function() {
            search();
        });
        $('select[name=filter-ss]').change(function() {
            search();
        });
    });

</script>

<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>
